#include<bits/stdc++.h>
#define ll long long
using namespace std;

int main(){
//    a a;
//    a.main();
    cout<<"test"<<endl;

    // anonymous func
    vector<int> a={1,2,3};
    auto t1=[&](vector<int> arr) ->void{for(auto x:arr)cout<<x<<" ";cout<<endl;}; t1(a);
    function<void(int)> dfs=[&](int u){for(auto v:a) dfs(v);};

    // number parse
    auto modParse=[&](int num)->vector<int>{vector<int> res; while(num!=0){res.push_back(num%10);num/=10;} return res;};
    auto stringParse=[&](int num)->vector<int>{vector<int> res; string tmp=to_string(num);for(char c: tmp){res.push_back(atoi(&c));} return res;};
    cout<<"numparse";t1(modParse(123));
    t1(stringParse(123));

    // vector
    a.push_back(4); t1(a);
    a.pop_back();t1(a);
    a.emplace_back(1ll);

    // priority queue
    priority_queue<vector<int>> pq;
    priority_queue<array<int, 3>> pq1;
    pq.push({a});
    pq1.push({a[0],a[1],a[2]});
    auto[x1,x2,x3]=pq1.top();
    auto x=pq.top();
    typeid(x);

    // hash
    pair<int,int> pi={1,2};
    cout<<pi.first<<" "<<pi.second<<endl;

    // for range, 0 <; 1 <=
    int b[]={1,2,3};
    for(int i=0;i<3;i++){
        cout<<b[i]<<" ";
    }; cout<<endl;

    // count
    string s="abc";
    int cnt=count(s.begin(),s.end(),'a'); cout<<cnt<<endl;

    // accumulate
    cout<<"accumulate([1,2,3]) is: "<<accumulate(a.begin(),a.end(),0); cout<<endl;
    // partial_sum
    auto c = partial_sum(a.begin()+1, a.end()-1, a.begin()+1);
    // upper_bound

    // *min_element
    cout<<min(1,2)<<endl;
    cout<<*min_element(a.begin(), a.end())<<endl;

    // fill
    int d[10]={}; fill(d,d+4,1); cout<<"fill is: ";
    for(int x:d) cout<<x<<' '; cout<<endl;
    vector<int> d_tmp={1,2,3};
    //            ranges::fill(diff, 0);
    fill(d_tmp.begin(), d_tmp.end(),0);

    // unorder_map contains 判断元素是否存在
    unordered_map<int,int> map_tmp={{1,2},{3,4}};
    if(map_tmp.find(1)!=map_tmp.end()) {cout<<"1 is exists";}
    else {cout<<"not exist";}
    if(map_tmp.count(1)!=0) {cout<<"1 is exists";}

    // put, putchar
    putchar('putex');putchar('\n'); puts("puts's exp");

    // sort
    vector<int> e ={4,3,2,1};
//    sort(e.begin(),e.end(), [&](int a,int b){return a>b;});
    cout<<*min(e.begin(), e.end())<<endl;
    sort(e.begin(),e.end(),greater());
    cout<<"sort: greater()"<<endl;
    for(auto i:e) cout<<i<<" "; cout<<endl;
    vector<pair<int,int>> f={{1,2},{2,4},{2,3}};
    for(auto i:f) cout<<i.first<<":"<<i.second<<", "; cout<<endl;
    sort(f.begin(),f.end(),[&](pair<int,int> a,pair<int,int> b){return a.first==b.first?a.second<b.second:a.first<b.first;});
    for(auto i:f) cout<<i.first<<":"<<i.second<<", "; cout<<endl;

    // atoi, toString
    vector<int> g={4,3,2,1};
    iota(g.begin(), g.end(),0);
    cout<<atoi("123")<<endl;
    cout<<to_string(234)<<endl;

    // int, float
    cout<< 1<<endl;
    cout<< (ll)(1<<20) <<endl;
    cout<< (ll)1<<20<<endl;

    // cout<<el<<"\n"[i==n-1] 打印所有元素后换行
    for(int i=0; i<g.size();i++) cout<<g[i]<<"\n"[i==g.size()-1];

    // multiset
    multiset<int> h ={1,2,3,'a'}; set<int>h1={1,2,3,'a'};

    // move 类型转换 左值引用转右值引用
    cout<<endl; queue<int> i={}; i.emplace(1);
    cout<<"move test: "<< i.front() <<endl;

    // assert() 断言 为假时终止编译或退出执行
    cout<<"assert exp: "<<endl;
//    for(auto i: h) {assert(i==2);cout<<i<<" "; } // 不输出1 提前退出
//    int t;cin>>t;while(t--) {int n; cin>>n; assert(n>0); cout<<n<<" ";}

    cout<<endl;
    putchar('a'); puts("abc");
    string str="abc";

    // sort, 第三个参数 comp 为 返回值的bool的匿名函数 通过 ?; || && 实现自定义排序
    vector<string> vs={"abc","ac","cde"};
    vector<int> vi={3,2,1};
    vector<pair<int,int>> vpii={{1,2},{2,3},{3,4}};
    sort(vi.begin(),vi.end(),[&](int a,int b)->bool{return a<b;});
    sort(vpii.begin(),vpii.end(),[&](pair<int,int> a, pair<int,int> b)->bool{a.first==b.first?a.second<b.second:a.first>b.first;});
    sort(vs.begin(),vs.end());

    // 与 异或常见用法：
    // 对输入参数做加法运算，但不能使用 +; 不创建临时变量交换两个数; a转换为b需要改多少位;
    // leetcode136 长度为n的数组arr中进一个出现两次的元素异或O(n), a^0=a; a^a=9
    // & 奇数&1=1; 偶数&1=0
    // & 相同数组与其负数值 a&-a: 当a==2的整数次幂 a&-a=a, 奇数 a&-a=1,
    cout<<"3 | 2 = "<<(3|2)<<endl;
    cout<<"3 & 2 = "<<(3&2)<<endl;
    cout<<(3||2)<<endl;
    cout<<(3&&2)<<endl;
    cout<<"3 ^ 2 = "<<(3^2)<<endl;
    cout<<"!3 = "<<(!3)<<endl;
    (1==1)? cout<<"right" : cout<<"wrong";
}